import Common from '../common.js'
import {Bounds} from './index.js'
function getPointBounds(shapes) {
  const bounds = new Bounds()
  forEachPoint(shapes, (p) => {
    bounds.mergePoint(p[0], p[1])
  })
  return bounds
}
function forEachPoint(shapes, cb) {
  let shp = null
  for (let i=0, n=shapes.length; i<n; i++) {
    shp = shapes[i]
    for (let j=0, m=shp ? shp.length : 0; j<m; j++) {
      cb(shp[j], i)
    }
  }
}
function transformPointsInLayer(lyr, f) {
  if (Common.layerHasPoints(lyr)) {
    forEachPoint(lyr.shapes, p => {
      const p2 = f(p[0], p[1])
      p[0] = p2[0]
      p[1] = p2[1]
    })
  }
}
export default {
  forEachPoint,
  getPointBounds,
  transformPointsInLayer,
}